package com.curvebreakers.wheresmystuff.activities;

import com.curvebreakers.wheresmystuff.R;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.app.FragmentTransaction;


public class WelcomeActivity extends UnauthorizedActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		ActionBar.Tab loginTab = actionBar.newTab().setText("Login");
		ActionBar.Tab registerTab = actionBar.newTab().setText("Register");
		loginTab.setTabListener(new TabsListener(new LoginFragment()));
		registerTab.setTabListener(new TabsListener(new RegistrationFragment()));
		actionBar.addTab(loginTab);
		actionBar.addTab(registerTab);		
	}
	
	/**
	 * ActionBar.TabListener implementation to switch the Login/Register tabs.
	 */
	private class TabsListener implements ActionBar.TabListener {
		public Fragment fragment;
		 
		public TabsListener(Fragment fragment) {
			this.fragment = fragment;
		}
		 
		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
			//DO NOTHING
		}
		 
		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragment);
		}
		 
		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			ft.remove(fragment);
		}
		 
	}

}
